"""
@author: ertao.xyz
@create: 2021-12-15 18:17
@description: 
"""

from tortoise import fields
from tortoise.models import Model

from core.model import AbstractBaseModel, TimestampMixin
from apps.user.model import User


class WechatMini(AbstractBaseModel, TimestampMixin):
    user = fields.ForeignKeyField('models.User', description='拥有者')
    name = fields.CharField(max_length=32, description='小程序名称', index=True)
    appId = fields.CharField(max_length=32, description='AppId', unique=True)
    appSecret = fields.CharField(max_length=32, description='AppSecret')
    wechatNo = fields.CharField(max_length=32, null=True, default=None, description='微信号码')
    contact = fields.CharField(max_length=32, null=True, default=None, description='联系方式')
    logo = fields.CharField(max_length=256, null=True, default=None, description='Logo')
    kefuCode = fields.CharField(max_length=32, null=True, default=None, description='客服二维码')
    wechatMiniCode = fields.CharField(max_length=32, null=True, default=None, description='小程序码')
    version = fields.CharField(max_length=10, null=True, default=None, description='版本')
    msgTongzhi = fields.CharField(max_length=32, null=True, default=None, description='消息通知模板ID')
    dingcanTongzhi = fields.CharField(max_length=32, null=True, default=None, description='订餐通知模板ID')
    fanliTongzhi = fields.CharField(max_length=32, null=True, default=None, description='返利通知模板ID')
    remark = fields.CharField(max_length=256, null=True, default=None, description='备注')
    aboutUs = fields.TextField(null=True, default=None, description='关于我们')
    state = fields.BooleanField(default=False, description='状态，true有效，false无效')

    def __str__(self):
        return self.name

    class Meta:
        table = "wechatMini"
        table_description = "微信小程序信息"
        ordering = ["-created_at"]

    class PydanticMeta:
        exclude = ["is_delete"]
